﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            allStudent = new List<Student>();
            var bindingList = new BindingList<Student>(allStudent);
            var source = new BindingSource(bindingList, null);
            dataGridView1.DataSource = source;
        }

        private List<Student> allStudent;

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Student item = new Student() { FullName = "Nguyen Van A", Age = 23 };
                allStudent.Add(item);
                var bindingList = new BindingList<Student>(allStudent);
                var source = new BindingSource(bindingList, null);
                dataGridView1.DataSource = source;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
